import genetic.Population;
import processing.core.PApplet;
import processing.core.PFont;

public class ShakesPeare extends PApplet {
	// Click mouse to add boids into the system

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public static void main(String args[]) {
		PApplet.main(new String[] { "--present", "ShakesPeare" });
	}

	PFont f, fb;
	String phrase;
	int popmax;
	float mutationRate;
	Population popul;

	public void setup() {
		size(700, 700);
//		fb = loadFont("Georgia-Bold-12.vlw");
//		f = loadFont("Arial-BoldMT-11.vlw");
		phrase = "To be or not to be.";
		popmax = 5000;
		mutationRate = 0.02f;

		// Create a population with a target phrase, mutation rate, and
		// population max
		popul = new Population(phrase, mutationRate, popmax);
	}

	public void draw() {
		// framerate(30);
		// Generate mating pool
		popul.naturalSelection();
		// Create next generation
		popul.generate();
		// Calculate fitness
		popul.calcFitness();
		displayInfo();

		// If we found the target phrase, stop
		if (popul.finished()) {
			noLoop();
		}
	}

	void displayInfo() {
		background(100);
		// Display current status of population
		String answer = popul.getBest();
//		textFont(fb);
		// textMode(SCREEN);
		textAlign(LEFT);
		fill(255);
		text(answer, 20, 100);

//		textFont(f);
		text("total generations: " + popul.getGenerations(), 20, 140);
		text("average fitness: " + popul.getAverageFitness(), 20, 155);
		text("total population: " + popmax, 20, 170);
		text("mutation rate: " + (int) (mutationRate * 100) + "%", 20, 185);
	}
}
